tsParticles - TypeScript Particles
A lightweight TypeScript library for creating particles. Dependency free (*) and browser ready!
Particles.js converted in TypeScript, dependency free (*), improved with new cool 😎 features and various bugs fixed and it's actively maintained!
Do you want to use it on your website?
This library is available on the two most popular CDNs and it's easy and ready to use, if you were using particles.js it's even easier.
You'll find the instructions below, with all the links you need, and don't be scared by TypeScript, it's just the source language.
The output files are just JavaScript. 🤩
CDNs and npm
have all the sources you need in Javascript, a bundle browser ready (tsparticles.min.js) and all files splitted for import
syntax.
If you are still interested some lines below there are some instructions for migrating from the old particles.js library.
Library installation
Hosting / CDN
Please use this hosts or your own to load tsParticles on your projects
jsDelivr
cdnjs
unpkg
https://unpkg.com/tsparticles/
npm
npm install tsparticles
yarn
yarn add tsparticles
Import and require
Starting from version 1.12.11 import
and require
can be used to import tsParticles
.
Now you can write something like this
const tsParticles = require("tsparticles");
import { tsParticles } from "tsparticles";
The imported tsParticles
is the same instance you have when including the script.
NuGet
Usage
Load tsParticles and configure the particles:
index.html
<div id="tsparticles"></div>
<script src="tsparticles.min.js"></script>
app.js
tsParticles
.loadJSON("tsparticles", "presets/default.json")
.then((container) => {
console.log("callback - tsparticles config loaded");
})
.catch((error) => {
console.error(error);
});
tsParticles.load("tsparticles", {
});
tsParticles.loadFromArray("tsparticles", [
{
},
{
},
]);
tsParticles.loadFromArray(
"tsparticles",
[
{
},
{
},
],
1
);
tsParticles.setOnClickHandler((event, particles) => {
});
const particles = tsParticles.domItem(0);
particles.play();
particles.pause();
Official components for some of the most used frameworks
Angular
ng-particles
You can find the instructions here
Inferno
inferno-particles
You can find the instructions here
jQuery
jquery-particles
You can find the instructions here
Preact
preact-particles
You can find the instructions here
ReactJS
react-tsparticles
You can find the instructions here
Svelte
svelte-particles
You can find the instructions here
VueJS 2.x
particles.vue
You can find the instructions here
VueJS 3.x
particles.vue3
You can find the instructions here
Templates and Resources
You can find some tsParticles related templates here. The templates are created for Vanilla Javascript, ReactJS, VueJS, Angular, SvelteJS and other frameworks.
The templates will may vary, new ones can be created or older ones updated with latest features or changed to a better style. Check them out once in a while.
If you created some good design with tsParticles feel free to submit a pull request with your cool template, you'll be credited as the template author!
https://github.com/tsparticles/templates
Demo / Generator
https://particles.js.org/Samples
Characters as particles
Mouse hover connections
Polygon mask
Animated stars
Nyan cat flying on scrolling stars
Snow particles
Background Mask particles
COVID-19 SARS-CoV-2 particles
Don't click! DON'T CLICK! OH NO IT'S SPREADING!!!!
COVID-19 is a serious disease. Please stay at home, wear a mask and stay safe!
particles.json
You can find a sample config here 📖
Options
You can find all options available here 📖
Want to see it in action and try it?
I've created a tsParticles collection on CodePen 😮 or you can checkout my profile
Otherwise there's the demo page link below. Just click/tap the Coronavirus below, don't be scared. It's safe 😷.
Want to see ever more demos? Clone the repository on your computer and follow these instructions
yarn install && yarn start
Boom! 💥 http://localhost:3000 and you can checkout other demos.
If you are brave enough you can switch to the dev
branch for trying the features under development.
Dependencies
You may have notices the * near dependency free. Well almost all features works without any dependency, but... Well there's a little but. The Polygon Mask feature requires pathseg
for some browsers to work fine, and obviously the Icon Fonts (like FontAwesome
) must be included in your page.
Migrating from Particles.js
tsParticles library is fully compatible with the particles.js configuration.
Seriously, you just need to change the script source et-voilà, you're ready 🧙!
You can read more here
Want to know 5 reasons to do the switch? Read here
Below you can find all the information you need to install tsParticles and its new syntax.
Plugins/Customizations
tsParticles now supports some customizations 🥳.
You can create your own plugins
_Read more here..._
API Docs
Documentation and Development references here 📖